//引入请求函数
import { http } from "@/utils/http";


/**
 * 订单页相关请求函数
*/
//@ts-ignore,引入类型约束
import type { preOrderResponse, orderDetailResponse, orderLogisticsResponse, orderListResponse } from "@/types/order.d.ts";



//获取预付订单
export const reqPreOrder = () => {
    return http<preOrderResponse>({
        url:"/member/order/pre",
        method:"GET"
    })
}

//获取立即购买订单
export const reqNowOrder = (skuId:string, count:string, addressId?:string) => {
    return http<preOrderResponse>({
        url:"/member/order/pre/now",
        method:"GET",
        data:{
            skuId,
            count,
            addressId
        }
    })
}

//获取再次购买订单
export const reqReOrder = (orderId:string) => {
    return http<preOrderResponse>({
        url:"/member/order/repurchase" + "/" + orderId,
        method:"GET"
    })
}



//提交订单
type goodItem = {
    skuId:string,
    count:number
}
type submitOrderRequestType = {
    goods:goodItem[],
    addressId:string,
    deliveryTimeType:number,
    buyerMessage:string,
    payType:number,
    payChannel:number
}
export const reqSubmitOrder = (data:submitOrderRequestType) => {
    return http<{id:string}>({
        url:"/member/order",
        method:"POST",
        data:data
    })
}

//获取订单详情
export const reqOrderDetail = (orderId:string) => {
    return http<orderDetailResponse>({
        url:"/member/order" + "/" + orderId,
        method:"GET"
    })
}

//获取订单列表
//page:页码  pageSize:页容量 orderState:订单状态(1:待付款,2:代发货,3:待收货,4:待评价,5:已完成,6:已取消,默认0:全部)
export const reqOrderList = (page?:number, pageSize?:number, orderState:number = 0) => {
    return http<orderListResponse>({
        url:"/member/order",
        method:"GET",
        data:{
            page,
            pageSize,
            orderState
        }
    })
}

//模拟发货--内测
export const reqConsignment = (orderId:string) => {
    return http({
        url:"/member/order/consignment" +"/"+ orderId,
        method:"GET"
    })
}

//订单确认收货-内测
export const reqOrderReceipt = (orderId:string) => {
    return http<orderDetailResponse>({
        url:"/member/order" + "/" + orderId + "/receipt",
        method:"PUT"
    })
}

//获取订单物流-内测开发中
export const reqOrderLogistics = (orderId:string) => {
    return http<orderLogisticsResponse>({
        url:`/member/order/${orderId}/logistics`,
        method:"GET"
    })
}

//删除订单-内测
export const reqDeleteOrder = (orderIds:string[]) => {
    return http({
        url:"/member/order",
        method:"DELETE",
        data:{
            ids:orderIds
        }
    })
}

//取消订单-内测
export const reqCancelOrder = (orderId:string) => {
    return http({
        url:"/member/order/" + orderId + "/cancel",
        method:"PUT"
    })
}




/*订单支付模块部分*/


//获取微信支付参数
type wxPayParamsResponse = {
    timeStamp:string,
    signType:string,
    package:string,
    paySign:string,
    nonceStr:string,
    appId:string
}
export const reqWxPayParams = (orderId:string) => {
    return http<wxPayParamsResponse>({
        url:"/pay/wxPay/miniPay",
        method:"GET"
    })
}

//模拟支付-内测
export const reqPayMock = (orderId:string) => {
    return http({
        url:"/pay/mock",
        method:"GET",
        data:{orderId}
    })
}